package com.isunland.managesystem.ui;

import com.google.gson.Gson;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.AttendanceType;
import com.isunland.managesystem.entity.CustomerDialog;
import java.util.ArrayList;

/**
 * 选择新建的考勤申请表类型
 *
 * @author wangyanan
 */
//public class RequisitionChooseDialogFragment extends DialogFragment {
//	protected static final int REQUEST_ADD = 100;
//	protected static final String EXTRA_TYPE = "com.isunland.managesystem.ui.RequisitionChooseDialogFragment";
//	private int[] choiceIds = new int[] { R.string.requisitionover,
//			R.string.requisitionunpunch, R.string.requisitionholy,
//			R.string.requisitiontrip, R.string.requisitionout,R.string.requisitionOff };
//	private String[] choiceStrings = new String[choiceIds.length];
//
//	@Override
//	public Dialog onCreateDialog(Bundle savedInstanceState) {
//		return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(
//				getChoiceName(), 0, new OnClickListener() {
//					@Override
//					public void onClick(DialogInterface dialog, int which) {
//
//						String type;
//						switch (which) {
//						case 0:
//
//							type = CheckDetailFragment.VALUE_OVER;
//							break;
//						case 1:
//							type = CheckDetailFragment.VALUE_UNPUNCH;
//							break;
//						case 2:
//							type = CheckDetailFragment.VALUE_HOLY;
//							break;
//						case 3:
//							type = CheckDetailFragment.VALUE_TRIP;
//							break;
//						case 4:
//							type = CheckDetailFragment.VALUE_OUT;
//							break;
//						case 5:
//							type = CheckDetailFragment.VALUE_OFF;
//							break;
//
//						default:
//							type = "";
//							break;
//						}
//
//
//						if (getTargetFragment() == null)
//							return;
//						Intent i = new Intent();
//						i.putExtra(EXTRA_TYPE, type);
//						getTargetFragment().onActivityResult(getTargetRequestCode(),
//								Activity.RESULT_OK, i);
//
//
//						dialog.dismiss();
//					}
//				}).create();
//
//	}
//
//	private String[] getChoiceName() {
//		for (int i = 0; i < choiceIds.length; i++) {
//
//			choiceStrings[i] = getResources().getString(choiceIds[i]);
//		}
//
//		return choiceStrings;
//	}
//
//}

public class RequisitionChooseDialogFragment extends BaseNetworkDialogFragment {
  protected static final String EXTRA_TYPE =
      "com.isunland.managesystem.ui.RequisitionChooseDialogFragment.EXTRA_TYPE";
  protected static final int REQUEST_ADD = 100;

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<>();
    AttendanceType[] attendanceTypes = new Gson().fromJson(arg0, AttendanceType[].class);
    if (attendanceTypes == null || attendanceTypes.length == 0) {

      return null;
    }
    for (int i = 0; i < attendanceTypes.length; i++) {
      list.add(new CustomerDialog(attendanceTypes[i].getName(), attendanceTypes[i].getValue(),
          attendanceTypes[i].getIfAllowSupplement()));
    }
    return list;
  }

  @Override public String getUrl() {
    return ApiConst.URL_ATTEND_TYPE;
  }
}

